package org.video.mine.mycode;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class HttpMethod {
    private static volatile OkHttpClient client;
    public static OkHttpClient getClient(){
        if (client == null){
            //log日志
            //设置https协议访问
            client = new OkHttpClient.Builder()
                    //过滤器
                    .addInterceptor(new Interceptor() {
                        @Override
                        public Response intercept(Chain chain) throws IOException {
                            Request request = chain.request()
                                    .newBuilder()
                                    .addHeader("App-Version","1.0.0")
                                    .addHeader("App-Type","SYN_MOBIOSPORT")
                                    .addHeader("accept", "application/json")
                                    .build();
                            return chain.proceed(request);
                        }
                    })
                    .sslSocketFactory(SSLSocketFactoryUtils.createSSLSocketFactory(),SSLSocketFactoryUtils.createTrustAllManager())
                    .hostnameVerifier(new SSLSocketFactoryUtils.TrustAllHostnameVerifier())
                    .readTimeout(5, TimeUnit.MINUTES)
                    .writeTimeout(5,TimeUnit.MINUTES)
                    .connectTimeout(20, TimeUnit.SECONDS)
                    .build();
        }
        return client;
    }
}
